Question 2- Plotly from Assignment 3

Assignment 3- Question 2

dat_class= read.table("https://raw.githubusercontent.com/bcaffo/ds4bme/master/data/classInterests.txt", header=TRUE)
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
class_plot <- ggplot(dat_class,aes(x=Year,fill= Program))
class_plot = class_plot + geom_bar()

ggplotly(class_plot)

Assignment 3- Question 3

library(ggmosaic)
dat_class= read.table("https://raw.githubusercontent.com/bcaffo/ds4bme/master/data/classInterests.txt", header=TRUE)
mosaic_class <- ggplot(data=dat_class) +
  geom_mosaic(aes(x=product(Year), fill = Program)) 

ggplotly(mosaic_class)

Assignment 3- Question 5

dat_health= read.csv("https://raw.githubusercontent.com/jhu-advdatasci/2018/master/data/KFF/healthcare-spending.csv", skip=2)
dat_health_states <- dat_health[-c(1,53:61),]
library(reshape)
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:plotly':
## 
##     rename
health_states_melt <- melt(dat_health_states, id.vars = "Location")
health_plot <- ggplot(health_states_melt,aes(x=variable, y=value, group= Location, color=Location))
health_plot = health_plot + geom_line()
health_plot = health_plot + theme(axis.text.x = element_text(angle = 90))

ggplotly(health_plot)

Assignment 3- Question 6

avg<- rowMeans(dat_health_states[,-1])
health_states_avg <-  data.frame(Location=dat_health_states[,1], Spending= avg)
health_barplot <- ggplot(health_states_avg, aes(x=Location, y=Spending))
health_barplot <- health_barplot + geom_col()
health_barplot = health_barplot + theme(axis.text.x = element_text(angle = 90))

ggplotly(health_barplot)